import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      name: "login",
      component: () => import("../views/home.vue"),
    },
    {
      path: "/menu",
      component: () => import("../views/menu.vue"),
      children: [
        {
          path: "refuel",
          component: () => import("../views/refuel.vue"),
        },
        {
          path: "life",
          component: () => import("../views/life.vue"),
        },
        {
          path: "refuel",
          component: () => import("../views/refuel.vue"),
        },
        {
          path: "user",
          component: () => import("../views/user.vue"),
        },
        {
          path: "order",
          component: () => import("../views/order.vue"),
        },
      ],
    },
    {
      path: "/map",
      component: () => import("../views/index.vue"),
    },
  ],
});

let whither = ["/"];

router.beforeEach((to, from, next) => {
  if (whither.includes(to.path)) {
    next();
  } else {
    if (localStorage.token) {
      next();
    } else {
      next("/");
    }
  }
});
// 导出
export default router;
